package com.zhengwl.study.sort;

/**
 * 
 * @author wlzheng
 * @description 找出最小的元素和最前位置的元素交换
 */
public class SelectSort implements Sort {

	private SortType sortType;

	public SelectSort() {
		sortType = SortType.SelectSort;
	}

	public void sort(int[] items) {
		selectSort(items);
	}

	// 直接选择排序
	public void selectSort(int[] items) {
		for (int i = 0; i < items.length; i++) {
			int minindx = i;
			for (int j = i; j < items.length; j++) {
				if (items[j] < items[minindx]) {
					minindx = j;
				}
			}
			swap(items, i, minindx);
		}
	}

	// 堆排序
	public void heapSort(int[] items) {
		for (int i = 0; i < items.length; i++) {
			int minindx = i;
			for (int j = i; j < items.length; j++) {
				if (items[j] < items[minindx]) {
					minindx = j;
				}
			}
			swap(items, i, minindx);
		}
	}

}
